package com.atldy.commerce.pojo;

import com.atldy.commerce.account.AddressItemVo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.Date;

/**
 * 用户地址表
 *
 * @TableName t_ecommerce_address
 */
@TableName(value = "t_ecommerce_address")
@Data
@ToString
public class EcommerceAddress implements Serializable {
    /**
     * 自增主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 用户 id
     */
    private Long userId;

    /**
     * 用户名
     */
    private String username;

    /**
     * 电话号码
     */
    private String phone;

    /**
     * 省
     */
    private String province;

    /**
     * 市
     */
    private String city;

    /**
     * 详细地址
     */
    private String addressDetail;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.UPDATE )
    private Date updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    /**
     * 将AddressItemVo转换为EcommerceAddress 做插入操作使用
     */
    public EcommerceAddress toEcommerceAddress(Long userId, AddressItemVo addressItemVo) {
        EcommerceAddress address = new EcommerceAddress();
        address.setUserId(userId);
        address.setUsername(addressItemVo.getUsername());
        address.setPhone(addressItemVo.getPhone());
        address.setProvince(addressItemVo.getProvince());
        address.setCity(addressItemVo.getCity());
        address.setAddressDetail(addressItemVo.getAddressDetail());

        return address;
    }

    /**
     * 将EcommerceAddress转换为AddressItemVo 做查询操作使用
     */
    public AddressItemVo toAddressItemVo() {
        AddressItemVo address = new AddressItemVo();
        address.setId(this.id);
        address.setUserId(this.userId);
        address.setUsername(this.getUsername());
        address.setPhone(this.getPhone());
        address.setProvince(this.getProvince());
        address.setCity(this.getCity());
        address.setAddressDetail(this.getAddressDetail());
        address.setCreateTime(this.createTime );
        address.setUpdateTime(this.updateTime);

        return address;
    }

}